<!-- messageWall -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表白墙</title>
</head>
<body>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        .container{
            width: 100%;
        }
        h3{
            text-align: center;
            padding: 20px 0;
            font-size: 24px;
        }
        p{
            text-align: center;
            color: #999;
            padding: 10px 0;
        }
        .row{
            width: 400px;
            height: 50px;
            margin: 0 auto;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .row span {
            width: 60px;
        }
        .row input{
            width: 300px;
            height: 40px;
            line-height: 40px;
            font-size: 20px;
            text-indent: 0.5em;
            /* 去掉轮廓线 */
            outline: none;
        }
        .row #submit {
            width: 350px;
            height: 40px;
            font-size: 20px;
            line-height: 40px;
            margin: 0 auto;
            color: white;
            background-color: orange;
            /* 去掉边框 */
            border: none;
            border-radius: 10px;
        }
        .row #submit:active{
            background-color: gray;
        }
    </style>
    <div class="container">
        <h3>表白墙</h3>
        <p>输入后点击提交,会将信息显示在表格中</p>
        <div class="row">
            <span>谁:</span>
            <input type="text">
        </div>
        <div class="row">
            <span>对谁:</span>
            <input type="text">
        </div>
        <div class="row">
            <span>说什么</span>
            <input type="text">
        </div>
        <div class="row">
            <button id="submit">提交</button>
        </div>
    </div>
    <script>
        //当用户点击submit,就会获取到input中的内容,从而把内容构造成一个div,插入到页面末尾
        let submitBtn = document.querySelector('#submit');
        submitBtn.onclick=function(){
            //1.获取到3个input中的内容
            let inputs=document.querySelectorAll('input');
            let from=inputs[0].value;
            let to=inputs[1].value;
            let msg=inputs[2].value;
            if(from==''||to==''||msg==''){
                //说明用户还没有填完,暂时先不提交数据
                return;
            }
            //2.生成一个新的div,内容就是input里面的内容,把这个新的div加载到页面中
            let div = document.createElement('div');
            div.innerHTML=from+'对'+to+'说'+msg;
            div.className='row';
            let container = document.querySelector('.container');
            container.appendChild(div);
            //3.清空之前输入框的内容
            for(let i=0;i<inputs.length;i++){
                inputs[i].value='';
            }
        }
    </script>

</body>
</html>